import Loading from '../components/loading.vue'

let el

export function showLoadingMask (timeout = 10000) {
  if (!el) {
    el = document.createElement('div')
    const container = document.createElement('div')
    el.appendChild(container)
    el.className = 'mu-modal-mask'
    el.style.background = 'transparent'
    el.style.zIndex = 99999;
    (() => new Vue({
      el: container,
      render: h => h(Loading)
    }))()
    document.body.appendChild(el)
    el.setAttribute('visible', '')
  } else {
    el.setAttribute('visible', '')
  }
  if (timeout < 1000) return
  setTimeout(() => {
    el?.removeAttribute('visible')
  }, timeout)
}

export function hideLoadingMask () {
  if (el) {
    el?.removeAttribute('visible')
  }
}
